package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.result.ResponseVo;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.entity.vo.BorrowerApprovalVo;
import com.atguigu.srb.core.pojo.entity.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-10-11
 */
@RestController
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {
    @Resource
    BorrowerService borrowerService;


    @ApiOperation("条件分页查询借款人列表")
    @GetMapping("{pageNum}/{pageSize}")
    public ResponseVo list(@PathVariable("pageNum")Integer pageNum,
                           @PathVariable("pageSize")Integer pageSize,
                            String key){
        Page<Borrower> page = new Page<>(pageNum,pageSize);
        borrowerService.listBorrowerByKey(page,key);
        return ResponseVo.ok().data("page",page);
    }

    @ApiOperation("根据借款人id查询借款人详情")
    @GetMapping("{id}")
    public ResponseVo getById(@PathVariable("id")Long id){
        BorrowerVO borrowerVO = borrowerService.queryBorrowerVoById(id);
        return ResponseVo.ok().data("item",borrowerVO);
    }

    @ApiOperation("借款人审批")
    @PostMapping("approval")
    public ResponseVo approval(@RequestBody BorrowerApprovalVo borrowerApprovalVo){
        borrowerService.approval(borrowerApprovalVo);
        return ResponseVo.ok();
    }
}

